<?php
/**
 * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

/**
 * Created by PhpStorm.
 * User: yf
 * Date: 2016/8/5
 * Time: 15:56
 */

namespace SDXApi\Controller;
use SDXApi\Service\Kingdee\GoodsStockQueryService;
use SDXApi\Service\SeminarService;
use SDXApi\Service\RecommendService;
use SDXApi\Service\UserBehavior;
use SDXApi\Service\OpensearchService;

//商品控制器
class GoodsController extends AppController {
    protected $wid = 8;
    public function _initialize($apptoken, $apptime)
    {
        parent::_initialize($apptoken, $apptime, false, '',true,false);
    }
    
    /**
     *
     *获取商品类型
     *
     */
    public function get_goods_class(){
        $category = M('category')->field('cat_id,cat_name')->where('is_show=1')->select();
        if($category){
            return_data($category,'','',count($category),'','success');
        }else{
            returnApiError("no data");
        }
    }

    /**
     *获取商品关键字
     */
    public function get_goods_keyword(){
        $category = M('keywords')->select();
        if($category){
            return_data($category,'','',count($category),'','success');
        }else{
            returnApiError("no data");
        }
    }

    /**
     *获取商品列表
     */
    public function get_goods_list(){
        $input = get_all_data_by_json();
        $page_current = !empty($input['page']) ? $input['page'] : 1;             //设置当前页数
        $page_size = !empty($input['page_size']) ? $input['page_size'] : 15;     //设置页大小

        //排序方式
        if(empty($input['order_key'])){
            $where['is_best'] =1;
        }else{
            $where['is_best'] =0;
        }

        //升降续
        if(empty($input['order_desc'])){
            $order_desc ="desc";    //降续
        }else{
            $order_desc ="dsc";     //升序
        }
        //精品
        if(!empty($input['is_best'])){$where['is_best'] =1;}else{$where['is_best'] =0;}
        //新品
        if(!empty($input['is_new'])){$where['is_new'] =1;}else{$where['is_new'] =0;}
        //热销
        if(!empty($input['is_hot'])){$where['is_hot'] =1;}else{$where['is_hot'] =0;}
        //特价促销
        if(!empty($input['is_promote'])){$where['is_promote'] =1;}else{$where['is_promote'] =0;}
        //商品分类
        if(!empty($input['category'])){$where['cat_id'] =$input['category'];}

        if($page_current<1) $page_current=1;        //约束页最小为1
        if($page_size<1) $page_size=1;              //约束页数据最小为1

        $start= ($page_current-1)*$page_size;

        $where['is_on_sale'] =1;    //销售状态
        $where['is_alone_sale'] =1; //单独销售
        $where['is_delete'] =0;     //未删除状态


        $good_list_count = M("goods")->where($where)->count();
        $good_list = M("goods")->where($where)->limit($start,$page_size)->order('last_update desc')->select();

        $page_all = ceil($good_list_count/$page_size);

        return_data($good_list,$page_size,$page_all,$good_list_count,$page_current,'SUCCESS');

    }
    
    
    /*
     * 商品详情
     * */
    public function goods_details(){
        $goods_id=I('post.goods_id', 0, 'int');
        $wid=I('post.wid',C('DEFAULT_WID'),'int');
        $uid=I('post.uid',0,'int');
        if(!isset($goods_id)){
            returnApiError('参数错误');
        }
        $res=D('goods')->get_goods_details($goods_id,$uid,$wid);
        $users = M("users")->field(true)->where(array("user_id"=>$uid))->find();
        $is_booking=D('Goods')->is_book_goods($goods_id,$uid,$users['mobile_phone']);
        $is_booking_depreciate=A('GoodsDepreciate')->is_book_goods($goods_id,$uid,$users['mobile_phone']);
        $comment=D("Evaluate")->get_goods_evaluate($goods_id,3);
        $res['comment']=$comment['goods'];
        $res['comment_count']=$comment['count'];
        if($is_booking){
            $res['is_booking']='1';
        }else{
            $res['is_booking']='0';
        }

        if($is_booking_depreciate){
            $res['is_booking_depreciate']='1';
        }else{
            $res['is_booking_depreciate']='0';
        }

        //获取用户余额信息
        $userinfo = M('users')->field('user_money')->where(array('user_id'=>$uid))->find();
        if(!empty($userinfo)){
            //如果用户余额低于配置的默认提示值，则提示用户充值
            if($userinfo['user_money'] <= C('BALANCE_LOWER_LIMIT_NOTICE')){
                $userinfo['need_notice_recharge'] = 1;
            }else{
                $userinfo['need_notice_recharge'] = 0;
            }
        }else{
            $userinfo['user_money'] = 0;
            $userinfo['need_notice_recharge'] = 0;
        }
        $res['userinfo'] = $userinfo;

        
        if($res){
            //添加到用户行为
            $hbv_type = I('post.source') == 'search' ? 'search_click' : 'click'; //判断是否为用户点击搜索结果中的物品
            $param = array('insertOne', $uid, $goods_id, I('wid') , $hbv_type, 1, 1);
            \Think\Hook::listen('receng', $param);

            returnApiSuccess($res);
        }else{
            returnApiError('查看商品详情错误');
        }
    }

	/**
	 * 获取商品详细描述
	 * Created by Jerry
	 */
    public function get_goods_desc_by_goods_id()
	{
		$goods_id = I('post.goods_id', 0, 'int');

		if (empty($goods_id)) {
			returnApiError('非法请求');
		}

		$goodsModel = D('Goods');

		$goods_desc = $goodsModel->find_goods_desc_by_goods_id($goods_id);

		if (empty($goods_desc)) {
			$goods_desc = '';
		}

//		$data = array(
//			'goods_desc'	=>	$goods_desc,
//		);

//		returnApiSuccess($data);
		header('Content-type: text/html; charset=utf-8');
		echo $goods_desc;
	}
    
    
    /*
     *限购商品详情 
     */
    
    public function quota_goods_details(){
    	if(!IS_POST){
    		returnApiError('error request');
    	}
    	
    	$act_id = I('post.act_id');
    	$goods_id = I('post.goods_id');
    	$uid=I('post.uid','intval');
    	$wid = I('post.wid',C('DEFAULT_WID'),'int');
    	$goods = D('goods');
    	$res = $goods->get_quota_goods_details($act_id,$goods_id,$uid,$wid);
    	if($res){
    		returnApiSuccess($res);
    	}else{
    		returnApiError('查看商品详情错误');
    	}
    }
    
    
    /*
     * 获取分类列表
     * */
    public function get_catelist(){
        $cat_id=I('post.cat_id');
        $is_hd = I('post.IS_HD');
        $uid = I('post.user_id',0,'int');
        $wid = I('post.wid',C('DEFAULT_WID'),'int');
        if(!isset($cat_id)){
            $cat_id=0;
        }
        $res=D('Category')->get_categorylist($cat_id,$is_hd,$uid,$wid);

        $default_show_index = C('DEFAULT_SHOW_INDEX');
        if($res){
            $res['show_index'] = !empty($default_show_index) ? $default_show_index : 0;
            returnApiSuccess($res);
        }else{
            returnApiError('查无数据');
        }
    }
    
    /*
     * 获取分类商品列表
     * */
    public function get_categoods_list(){
        $cat_id=I('post.cat_id');
        $wid=I('post.wid',C('DEFAULT_WID'),'int');
        $uid = I('post.uid', 0, 'int');
        $is_hd = I('post.IS_HD');
        if($is_hd){
            $from = 'hd';
        }else{
            $from = 'web';
        }

        if(!isset($cat_id)){
            returnApiError('参数错误');
        }
        $page=I('post.page','int');

        
        $res=D('Category')->get_category_goodslist($cat_id,$page,$from,'',$wid, false, false, $uid);
        //dump($res);
        if(!empty($res)){
            returnApiSuccess($res);
        }else{
            $tag_array = D('Goods')->get_goods_tag_by_category($cat_id,null,true);
            if($tag_array){
                //存在商品标签（标签里面有商品）
                $tag_name = $tag_array[0]['tag_name'];
                $re = D('Category')->get_category_goodslist($cat_id,$page,$from,'',$wid,$tag_name, false, $uid);
                if($re){



                    returnApiSuccess($re);
                }else{
                    returnApiError('查无数据');
                }
            }else{
                returnApiError('查无数据');
            }
        }
    }
    
    /*获取促销商品列表*/
    public function get_salesgoods_list(){
        $salestype=I('post.salestype','intval');
        if(!isset($salestype)){
            returnApiError('参数错误');
        }
        $page=I('post.page',1,'int');
        $wid=I('post.wid',C('DEFAULT_WID'),'int');
        $res=D('Goods')->select_salesgoods_list($salestype,$page,$wid);
        if($res){
            returnApiSuccess($res);
        }else{
            returnApiError('查无数据');
        }
    }
    
    /*收藏商品*/
    public function collect_goods(){
        parent::check_uid();
        $uid=$this->uid;
        $goods_id=I('post.goods_id','intval');
        $wid=I('post.wid',C('DEFAULT_WID'),'int');
        if(!isset($uid) || !isset($goods_id)){
            returnApiError('参数错误');
        }
        $this->uid=$uid;
        $res=D('Goods')->get_collect_goods($uid,$goods_id,$wid);
        if($res){

            //添加到用户行为
            $param = array('insertOne', $uid, $goods_id, I('wid') , 'collect', 1, 1);
            \Think\Hook::listen('receng', $param);

            returnApiSuccess(array('id'=>$res));
        }else{
            returnApiError('收藏失败');
        }
    }

    //批量收藏商品
    public function collect_goods_batch(){
        parent::check_uid();
        $uid=$this->uid;
        $goods_ids=I('post.goods_ids');
        $wid=I('post.wid',C('DEFAULT_WID'),'int');
        if(empty($uid) || empty($goods_ids)){
            returnApiError('参数错误');
        }

        $goods_id_list = explode(',',$goods_ids);

        $delete_goods_id = array();
        if(is_array($goods_id_list)){
            foreach($goods_id_list as $goods_id){
                $res=D('Goods')->get_collect_goods($uid,$goods_id,$wid);
                if($res!==false){
                    //添加到用户行为
                    $param = array('insertOne', $uid, $goods_id, I('wid') , 'collect', 1, 1);
                    \Think\Hook::listen('receng', $param);
                }
            }
            $delete_goods_id = $goods_id_list;
        }else{
            $goods_id = $goods_id_list;
            $res=D('Goods')->get_collect_goods($uid,$goods_id,$wid);
            if($res!==false){
                //添加到用户行为
                $param = array('insertOne', $uid, $goods_id, I('wid') , 'collect', 1, 1);
                \Think\Hook::listen('receng', $param);
            }
            $delete_goods_id[] = $goods_id;
        }

        if(count($delete_goods_id)>0){
            //从购物车中删除
            $map = array();
            $map['goods_id'] = array('in',$delete_goods_id);
            M('cart')->where('goods_id')->where($map)->delete();

            returnApiSuccess('','收藏商品成功');
        }else{
            returnApiError('收藏商品失败');
        }
    }
    
    /*取消收藏商品*/
    public function cancelcollect_goods(){
        parent::check_uid();
        $uid=$this->uid;
        $goods_id=I('post.goods_id','intval');
        $wid=I('post.wid',C('DEFAULT_WID'),'int');
        if(!isset($uid) || !isset($goods_id)){
            returnApiError('参数错误');
        }
        $res=D('Goods')->cancel_collect_goods($uid,$goods_id,$wid);
        if($res){

            //添加到用户行为
            $param = array('insertOne', $uid, $goods_id, I('wid') , 'uncollect', 1, 1);
            \Think\Hook::listen('receng', $param);

            returnApiSuccess(array('id'=>$res));
        }else{
            returnApiError('取消收藏商品失败');
        }
    }

    /**
     * 返回搜索热词
     * @return json
     */
    public function get_search_hot_keyword()
    {
        $uid=I('post.uid', 0, 'int');

        $opensearch = new OpensearchService();
        $hots = $opensearch->get_search_hot_keyword($uid);

        if(empty($hots)){
            returnApiError('暂无搜索热词');
        }

        $data = array(
            'searchHots'    =>  $hots,
        );

        returnApiSuccess($data);
    }


    /**
     *返回搜索结果
     * @return json
     */
    public function  search_goods(){
    	$keyword=I('post.keyword');
    	$uid =I('post.uid');
    	if(!isset($keyword)){
    		returnApiError('参数错误');
    	}

//    	统计搜索热词
        $hotId = I('post.hot_id', 0, 'intval');
        if(!empty($hotId)){
            $hotModel = D('SearchHot');
            $hotModel->add_search_hot_count($hotId);
        }
    	
    	//记录搜索记录
    	if(!empty($keyword)){
    		$search_data = array();
    		$search_data['uid'] = $uid;
    		$search_data['keyword'] = $keyword;
    		$search_data['searchengine'] = "ECTouch";
    		$search_data['create_time'] = gmtime();
    		$search = M('search_keyword');
    		$search->add($search_data);
    	}
    	$page=I('post.page',1,'intval');
    	$wid=I('post.wid',C('DEFAULT_WID'),'int');

        $goodsModel = D('Goods');
    	$goodsList = $goodsModel->get_searchgoods($keyword,$page,$wid, $this->uid);
        //增加分类结果
        $catModel = D('category');
        $catList = array('catelist' => $catModel->get_search_cat_list($keyword));

        $data = array_merge($goodsList, $catList);

        if($data){

            //添加到用户行为
            $param = array('isertList', $uid, 'view', $goodsList['goodssaleslist'], I('wid'));
            \Think\Hook::listen('receng', $param);

            returnApiSuccess($data);

        }else{
            returnApiError('查无数据');
        }
    	
    }

    /**
     *返回分类/品牌搜索结果
     * @return json
     */
    public function search_goods_cate()
    {
        if(!IS_POST){
            returnApiError('非法操作');
        }
        $catId = I('post.cid');
        $brand_id = I('post.brand_id');
        $goods_id = I('post.goods_id');
        $is_cart_use = I('post.is_cart_use');
        $keyword = I('post.keyword');
        $page=I('post.page',1,'int');
        $wid=I('post.wid',C('DEFAULT_WID'),'int');
        $uid=I('post.uid');
        $act_id=I('post.act_id',0,'int');
        $goodsModel = D('Goods');
        $data = $goodsModel->get_search_goods_by_cat($keyword, $wid, $catId, $page, $uid,$brand_id,$goods_id,$is_cart_use,$act_id);

        if(empty($data)){
            returnApiError('暂无结果');
        }

        //添加到用户行为
        $param = array('isertList', $uid, 'view', $data['goodssaleslist'], $wid);
        \Think\Hook::listen('receng', $param);

        returnApiSuccess($data);
    }
    


    /**
     *缺货登记
     */
    public function booking_goods(){
        $goods_id = I('post.goods_id');
        $wid = I('post.wid',C('DEFAULT_WID'),'int');
        if (empty($goods_id)) returnApiError("goods_id is null");
        
        $goods_inventory1=M("goods")->where(array('is_presell'=>'1','goods_id'=>$goods_id))->getField('goods_number');
        $goods_inventory2=M("goods_storage")->where(array('wid'=>$wid,'goods_id'=>$goods_id))->getField('practical_num');

        if(($goods_inventory1+$goods_inventory2)>0){
            returnApiError('商品有货，不可以登记到货通知');
        }
        

        $user_phone = D("Goods")->get_user_phone($this->uid);
        if (empty($user_phone)) returnApiError('phone is null');
        $res=D("Goods")->book_goods($goods_id,$this->uid,$user_phone,$wid);
        if($res){
            returnApiSuccess(null,'登记成功，到货将以短信通知');
        }else{
            returnApiError('您已登记，到货将以短信通知');
        }
    }
    

    /**
     *获取商品标签（根据商品分类ID）
     */
    public function get_goods_tag(){

        $relation_type = I('post.relation_type');
        $wid=I('post.wid', C('DEFAULT_WID'), 'int');

        if (empty($relation_type)) returnApiError("商品ID为空");

        $res['list'] = D("Goods")->get_goods_tag_by_category($relation_type,$wid);
        if($res){
            returnApiSuccess($res,'标签返回成功');
        }else{
            returnApiError('未找到标签');
        }
    }

    /**
     *按商品标签查询商品列表.
     */
    public function get_goods_by_tag(){
        $cat_id=I('post.cat_id');
        $tag_name=I('post.tag_name');
        $wid=I('post.wid', C('DEFAULT_WID'), 'int');
        if(!isset($tag_name)||!isset($cat_id)){
            returnApiError('参数错误');
        }
        $page=I('post.page','intval');
        $res=D('Category')->get_category_goodslist($cat_id,$page,'web','',$wid,$tag_name, false, $this->uid);
        if($res){
            returnApiSuccess($res);
        }else{
            returnApiError('查无数据');
        }
    }

    /**
     *按首写字母查找商品
     */
    public function get_categoods_list_by_first_letter(){
        $first_letter=I('post.first_letter');
        $wid=I('post.wid',C('DEFAULT_WID'), 'int');
        if(!isset($first_letter)){
            returnApiError('参数错误');
        }
        $page=I('post.page','intval');
//        $first_letter = substr($first_letter,0,1);
        $res=D('Category')->get_category_goodslist(null,$page,'web','',$wid,null,$first_letter, $this->uid);

        if($res){
            returnApiSuccess($res);
        }else{
            returnApiError('查无数据');
        }
    }
    
    /**
     * 获取热门搜索关键
     */
    public function get_hot_keyword(){
    	$uid = I("post.uid");
    	$wid = I("post.wid",C('DEFAULT_WID'),'int');
    	$keyword = array(
    			"番茄","蒜头","菜心","豆角","豆腐","苹果","橙","奇异果","火龙果","米","油","五花肉","牛排","带鱼","老干妈","酱油","核桃","开心果","汤料","下午茶"
    	);
    	$result["keyword"] = $keyword;
    	returnApiSuccess($result);
//        $this->get_search_hot_keyword();
    }

    /**
     * 根据商品货号获取商品ID
     * POPTSER
     */
    public function get_goods_id_by_sn(){
        $goods_sn = I('post.goods_sn');
        if(!empty($goods_sn)){
            $goods_id = M("goods")->where(array("goods_sn"=>$goods_sn))->find();
            if($goods_id){
//                if(empty($goods_id['goods_thumb'])||$goods_id['is_on_sale']!=1){
//                    returnApiError("此商品仅限线下购买");
//                }
                $data['goods_id'] = $goods_id['goods_id'];
                returnApiSuccess($data,"成功找到商品ID");
            }else{
                returnApiError("未找到该商品");
            }
        }else{
            returnApiError("商品货号有误");
        }
    }

    /*
     * 热销商品（同类品牌推荐、同类热销商品、相关专题）
     * Created by caicm
     */
    public function get_hot_sell_goods(){
        $test_data = array();
        $brand_list = array();
        $goods_id = I('post.goods_id',0,'int');
        $wid = I("post.wid",C('DEFAULT_WID'),'int');
        $uid = I('post.uid',0, 'int');
        $brand_id = I('post.brand_id',0,'int');
        $cat_id = I('post.cat_id',0,'int');
        if(!$goods_id ){
            returnApiError('参数错误');
        }


        //参与的专题
        $seminarService = new SeminarService();
        $return_data['seminar_list'] = $seminarService->getSeminarGoodsListByGoodsId($goods_id);

        $recommend = new RecommendService();
        //同类商品
        $brand_list = $recommend->get_list('similarity', $uid, $goods_id, 6, $wid, 1);
        $return_data['brand_list'] = $brand_list['goods_list'];

        //阿里推荐返回数据不足
        if(count($return_data['brand_list'])<6){
            $brand_list = $brand_list['goods_list'] ? $brand_list['goods_list'] : array();
            //同类品牌推荐
            if($brand_id) $brand_list = D('Goods')->get_hot_sell_goods($wid, $uid, $goods_id, 'brand', $brand_id, 6);

            //处理品牌数据小于6条拉取 同类3级分类商品
            if($brand_list){
                $num = count($brand_list);
            }else{
                $num = 0;
                $brand_list = array();
            }

            if($num<6){

                //当前分类其他商品
                $test_data = D('Goods')->get_hot_sell_goods($wid, $uid, $goods_id, 'category', $cat_id, 6-$num);


            }

            $return_data['brand_list'] = array_merge($brand_list, $test_data);
        }

        //同类热销商品
        $category_list = $recommend->get_list('hot_sell', $uid, $goods_id, 6, $wid, 1);
        $return_data['category_list'] = $category_list['goods_list'];

        //阿里推荐返回数据不足
        if(count($return_data['category_list'])<6){
            //获取2级分类id
            $cat_id = D('category')->findLevelCatId($cat_id, 2);

            //获取当前分类的所有子分类
            $cid_array = S('category_child_cat_id_by_parentid_'.$cat_id);
            if(empty($cid_array)){
                $cat_list = D('category')->cat_list($cat_id,0,false,0,false);
                $cid_array=array();
                foreach ($cat_list as $cate_val){
                    $cid_array[] = $cate_val['cat_id'];
                }
                $cid_array = array_unique($cid_array);
                S('category_child_cat_id_by_parentid_'.$cat_id,$cid_array,3600);
            }


            $val = implode(',', $cid_array);
            //同类热销商品
            $return_data['category_list'] = D('Goods')->get_hot_sell_goods($wid, $uid, $goods_id, 'category', $val, 6);

        }

        $return_data['seminar_list'] = $return_data['seminar_list'] ? $return_data['seminar_list'] : array();
        $return_data['category_list'] = $return_data['category_list'] ? $return_data['category_list'] : array();
        $return_data['brand_list'] = $return_data['brand_list'] ? $return_data['brand_list'] : $return_data['category_list'];


        //添加到用户行为(同类品牌)
        if($return_data['brand_list']){
            $param = array('isertList', $uid, 'view', $return_data['brand_list'], $wid, 3, '', $goods_id);
            \Think\Hook::listen('receng', $param);
        }

        //添加到用户行为(同类热销商品)
        if($return_data['category_list']){
            $param = array('isertList', $uid, 'view', $return_data['category_list'], $wid, 4, '', $goods_id);
            \Think\Hook::listen('receng', $param);
        }


        returnApiSuccess($return_data);
    }

    /**
     * 浏览商品足迹
     * poptser@foxmail.com
     */
    public function goods_footprint(){

        $page = I('post.page');
        $page_size = I('post.page_size');
        $page_current = !empty($page) ? $page : 1;             //设置当前页数
        $page_size = !empty($page_size) ? $page_size : 15;     //设置页大小
        $uid=I('post.uid',0,'int');
        $wid = I('post.wid', 8, 'int');
        if(empty($uid)){
            returnApiError("用户ID不存在");
        }

        if($page_current<0){
            $page_current = 1;
        }
        if($page_size<0){
            $page_size = 15;
        }
        $start = ($page_current-1)*$page_size;


//        $good_list_count = M("user_behavior")->where(array("user_id"=>$uid,"bhv_type"=>"click","is_show"=>0))->count();
//
//        $good_id_list = M("user_behavior")->where(array("user_id"=>$uid,"bhv_type"=>"click","is_show"=>0))->field("bhv_datetime,item_id,add_time")->limit($start,$page_size)->order('add_time desc')->select();
//
//        dump(M("user_behavior")->getLastSql());

        //$good_list_count = M("user_behavior")->where(array("user_id"=>$uid,"bhv_type"=>"click","is_show"=>0))->group("TO_DAYS(from_unixtime(add_time+ 28800)),item_id")->count();

        $good_id_list = M("user_behavior")->where(array("user_id"=>$uid,"bhv_type"=>"click","is_show"=>0))->field("bhv_datetime,item_id,MAX(add_time) as add_time")->limit($start,$page_size)->group("TO_DAYS(from_unixtime(add_time+ 28800)),item_id")->order('id desc')->select();

//        dump(M("user_behavior")->getLastSql());


        //添加行为
        $user_bevavior = new UserBehavior();
        $user_bevavior->add_browse($uid, 34);

        if(empty($good_id_list)){
            returnApiError("无足迹数据");
        }

        $new_goods_data = array();
        $new_goods_data_t = array();
        $new_goods_id_list = array();
        foreach ($good_id_list as $key=>$value){
            $new_goods_data[$key]= $value['add_time']+28800;
            $new_goods_data_t[$key]= $value['bhv_datetime'];
            $new_goods_id_list[] = $value['item_id'];
        }



        $goods_list = D('Goods')->get_search_goods_by_id(implode(',', $new_goods_id_list), $uid, $this->wid);

        //处理金蝶商品库存
        $goodsStockQueryService = new GoodsStockQueryService();
        $goods_list = $goodsStockQueryService->getGoodsStockList($wid, $goods_list);

        foreach ($goods_list as $key=>$value){
            $goods_list[$key]['bhv_datetime'] = $new_goods_data_t[$key];
        }
        $new_goods_list = array();

        foreach ($goods_list as $key=>$value){
            if($_POST['is_h5']==1){
                $key = "d".date('Ymd', $new_goods_data[$key]);
            }else{
                $key = date('Y-m-d', $new_goods_data[$key]);
            }

            $new_goods_list[$key][] = $value;
        }


        $data['goods_list'] = $new_goods_list;
        $data['page'] = array(
            "current" =>  $page_current,
            "page_size" => $page_size,
            "page_count" => 0,
        );
        if(count($good_id_list)<15){
            $data['is_bottom'] = 1;
        }else{
            $data['is_bottom'] = 0;
        }
        returnApiSuccess($data,"已返回足迹");


    }

    /**
     * 清除足迹
     * poptser@foxmail.com
     */
    public function clear_footprint(){
        $uid=I('post.uid',0,'int');
        if(empty($uid)){
            returnApiError("用户ID不存在");
        }else{
            $re = M("user_behavior")->where(array("user_id"=>$uid))->setField("is_show",1);
            if($re){

                //添加行为
                $user_bevavior = new UserBehavior();
                $user_bevavior->add_browse($uid, 35);
                returnApiSuccess(null,"清除成功");
            }else{
                returnApiError("清除失败");
            }
        }
    }

}